﻿<cfsilent>

	<cfscript>
	
		event.setArg("pageTitle", "教学运行管理 - 学期课程安排 - 计划课程排课");
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		
		taskProp = getProperty("serviceFactory").getBean("taskPropertyAdvice");
		
		termId = event.getArg("TID");
		courseId = event.getArg("CID");
		taskId = event.getArg("TSK");
		period = event.getArg("PR");
		filter = event.getArg("FT");
		depId = event.getArg("DEP");
		courseProp = event.getArg("CP");

		sql = "	SELECT
					t.term_id,t.academic_year,t.academic_term,t.term_prop
				FROM
					t_term t
				WHERE
					t.term_id = :termId ";
		
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
		rs_targetTermEntity = queryObj.execute(sql = sql).getResult();
		
		/* 排课可用时间 */
		timeTable = event.getArg("timeTable");
		
		/* 
			课程筛选条件 周学时 period 具备排他性
		*/
		HSQLperiod = "AND c.task_period != '0' ";
		
		/* 选择了周学时 */
		if ( period neq "" ) {
			HSQLperiod = "AND c.task_period = '" & period & "' ";
		}

		/* 
			课程筛选条件 逻辑条件 filter 具备复合型
		*/
		HSQLfilter = "";
		
		/* 填写了排课要求 */
		if ( listFind( filter, "ArrangeDescribe", "," ) ) {
			HSQLfilter = HSQLfilter & "AND c.task_desc IS NOT NULL ";
		}
		
		/* 未安排上课地点 */
		if ( listFind( filter, "NoPlace", "," ) ) {
			HSQLfilter = HSQLfilter & "AND c.task_place IS NULL ";
		}
		
		/* 未排课 */
		if ( listFind( filter, "ToArrange", "," ) ) {
			HSQLfilter = HSQLfilter & "AND a.period_done < a.period_need AND a.period_done = 0 ";
		}
		
		/* 学时未排够 */
		if ( listFind( filter, "UnComplate", "," ) ) {
			HSQLfilter = HSQLfilter & "AND a.period_done < a.period_need AND a.period_done > 0 ";
		}
		
		/* 学时排多 */
		if ( listFind( filter, "OverPeriod", "," ) ) {
			HSQLfilter = HSQLfilter & "AND a.period_done > a.period_need AND a.period_done > 0 ";
		}
		
		
		/* 
			课程性质筛选条件 课程性质 courseProp 具备排他性
		*/
		
		/* 必修课 */
		if ( courseProp eq "Required" ) {
			HSQLfilter = HSQLfilter & "AND EXISTS(SELECT 1 FROM t_plan b WHERE co.cid = b.cid AND a.term_id = b.term_id AND b.prop_id = '1') ";
		}
		
		/* 选修课 */
		if ( courseProp eq "Optional" ) {
			HSQLfilter = HSQLfilter & "AND EXISTS(SELECT 1 FROM t_plan b WHERE co.cid = b.cid AND a.term_id = b.term_id AND b.prop_id = '2') ";
		}
		
		/* 
			开课学院筛选条件 任课单位 depId 具备排他性
		*/
		HSQLdep = "";
		
		if ( len(depId) ) {
			HSQLdep = "AND coi.institute_id = '" & depId & "' ";
		}

		sql = "	SELECT
					co.cid,co.course_name,co.course_credit,coi.institute_short
				FROM
					t_task_arrange a
					INNER JOIN t_course co ON a.cid = co.cid
					INNER JOIN t_institute coi ON coi.institute_id = co.institute_id
				WHERE
					a.term_id = :termId  
					"
					&
					HSQLdep
					& 
					" AND
						EXISTS(
							SELECT 0 FROM
								t_task c
							WHERE
									c.tsk_id = a.task_id  "
									& HSQLperiod 
									& HSQLfilter 
									&"AND
									SUBSTR(c.task_prop,7,1) = '0'
						)
				GROUP BY
					co.cid,co.course_name,co.course_credit,coi.institute_short
				ORDER BY
					coi.institute_short,co.course_name";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
		rs_course = queryObj.execute(sql = sql).getResult();

		/* 所有课程的开课学院 */
		sql = "	SELECT
					DISTINCT i.institute_id,i.institute_short
				FROM
					t_task a
					INNER JOIN t_course c ON c.cid = a.cid
					INNER JOIN t_institute i ON i.institute_id = c.institute_id
				WHERE
					a.term_id = :termId 
					AND
					EXISTS(SELECT 1 FROM t_task_arrange ta WHERE a.tsk_id = ta.task_id)
				ORDER BY
					i.institute_short";

		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
		rs_dep = queryObj.execute(sql = sql).getResult();

		/* 所有课程的周学时 */
		sql = "	SELECT
					DISTINCT a.task_period
				FROM
					t_task a
				WHERE
					a.term_id = :termId 
					AND
						EXISTS(SELECT 1 FROM t_task_arrange b WHERE a.tsk_id = b.task_id)
				ORDER BY
					a.task_period DESC";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
		rs_period = queryObj.execute(sql = sql).getResult();
		
		/* 指定一个默认课程 */
		if ( courseId eq "" and rs_course.recordCount ) { courseId = rs_course['cid'][1]; }
		
		sql = "	SELECT
					c.course_name,i.institute_name,c.period,c.period_theory,c.course_credit
				FROM
					t_course c
					INNER JOIN t_institute i ON c.institute_id = i.institute_id
				WHERE
					c.cid = :courseId ";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "courseId", value = courseId, cfsqltype = "cf_sql_varchar");
		rs_targetCourseEntity = queryObj.execute(sql = sql).getResult();
		
		currentTab = event.getArg("Tab", "labArrang");

		passArgs = structNew();
		structInsert(passArgs, "TID", termId, true);
		
		if ( period neq "" ) { structInsert(passArgs, "PR", period, true); } 
		if ( filter neq "" ) { structInsert(passArgs, "FT", filter, true); }
		if ( depId neq "" ) { structInsert(passArgs, "DEP", depId, true); }
		if ( courseProp neq "" ) { structInsert(passArgs, "CP", courseProp, true); }
		
		if ( rs_course.recordCount ) {
			
			/* 计算排课进度 */
			sql = "	SELECT
						SUM(b.period_need) n_sum,
						SUM(CASE WHEN b.period_done > b.period_need THEN b.period_need ELSE b.period_done END) d_sum
					FROM
						t_task_arrange b
					WHERE
							b.term_id = :termId 
						AND
							b.task_type = 'P'
						AND
						   	EXISTS(SELECT 1 FROM t_task a WHERE a.tsk_id = b.task_id AND SUBSTR(a.task_prop,7,1) = '0' )";
			
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
			rs_check = queryObj.execute(sql = sql).getResult();
			
			prog = min(100, 100 * rs_check['d_sum'][1]/rs_check['n_sum'][1]);
			progL = 1;
			
			if ( prog gt 0 and prog lte 25 ) { progL = 2; }
			if ( prog gt 25 and prog lte 50 ) { progL = 3; }
			if ( prog gt 50 and prog lte 75 ) { progL = 4; }
			if ( prog gt 75 and prog lte 100 ) { progL = 5; }
		}

		taskArray = [];
		
		showCourseArrangeMode = false;

		rs_task = queryNew("task_id");
		
		if (rs_targetCourseEntity.recordCount) {
			
			sql = "	SELECT
						a.task_id,
						ac.course_name,
						btch.tch_name,
						a.cidx,
						b.task_week,
						a.period_need,
						a.period_done,
						CASE WHEN b.task_time IS NULL THEN '-' ELSE b.task_time END task_time,
						CASE WHEN b.task_place IS NULL THEN '-' ELSE b.task_place END task_place,
						b.task_period,
						CASE WHEN b.task_desc IS NULL THEN '-' ELSE b.task_desc END task_desc,
						ac.cid,
						a.task_type,
						b.task_limite,
						b.task_prop,
						bct.cr_type_name,
						bca.campus_name,
						b.task_mode,
						b.task_chooesd
					FROM
						t_task_arrange a INNER JOIN t_course ac ON ac.cid = a.cid,t_task b INNER JOIN t_teacher btch ON b.tch_id = btch.tch_id 
						INNER JOIN t_classroom_type bct ON b.cr_type = bct.cr_type INNER JOIN t_campus bca ON bca.campus_id = b.campus_id
					WHERE
						a.task_id = b.tsk_id
						AND
						a.term_id = :termId 
						AND 
						a.cid = :courseId 
					ORDER BY
						btch.tch_name";

			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
			queryObj.addParam(name = "courseId", value = courseId, cfsqltype = "cf_sql_varchar");
			rs_task = queryObj.execute(sql = sql).getResult();

			for(a = 1; a lte rs_task.recordCount; a++){
				if ( rs_task['task_mode'][a] eq "1" ) {
					showCourseArrangeMode = true;
					break;
				}
			}
			
		}

	</cfscript>

</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 course"></i><cfoutput>#rs_targetTermEntity.academic_year#</cfoutput>-<cfoutput>#dictAdvice.getTerm(rs_targetTermEntity.academic_term)#</cfoutput> 计划课程安排
				</h2>
			</div>
		</div>
	</div>
</div>

<!--- 加载导航菜单 --->
<!-- stepMenu-->
<cfoutput>#event.getArg("stepMenu")#</cfoutput>
<!--/stepMenu-->

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				
				<div class="UItab2">
					<div class="tabLables">
						<span <cfif currentTab eq "labArrang">class="active"</cfif> id="labArrang" tabTarget="Arrange">课程安排</span>
						<span <cfif currentTab eq "labTimeSet">class="active"</cfif> id="labTimeSet" tabTarget="TimeSet">设置排课可用时间</span>
						<cfif taskId neq "">
							<span <cfif currentTab eq "labCourseTable">class="active"</cfif> id="labCourseTable" tabTarget="CourseTable">人机交互排课</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Arrange" class="tabContent">
					
					<div class="noticeBlock">
						
						<div class="UIArrangeOper mtl">
						
							<b class="lable">周学时</b>
							<div class="content">
								
								<cfset resetArgs = duplicate( passArgs ) />
								
                                <cfloop query="rs_period">
									<cfset structInsert( resetArgs, "PR", rs_period.task_period, true ) />
									<cfif period eq rs_period.task_period>
										<span class="opBtn numeric"><cfoutput>#rs_period.task_period#</cfoutput></span>
										<cfelse>
										<a class="opBtn numeric" href="<cfoutput>#buildURL('planTask', resetArgs)#</cfoutput>"><cfoutput>#rs_period.task_period#</cfoutput></a>
									</cfif>
								</cfloop>

								<cfset structDelete( resetArgs, "PR", false ) />
								<cfif event.isArgDefined("PR")>
									<a class="opBtn" href="<cfoutput>#buildURL('planTask', resetArgs)#</cfoutput>">不限</a>
								</cfif>
							</div>
						</div>
						
						<div class="UIArrangeOper">
						
							<b class="lable">任课单位</b>
							<div class="content">
								
								<cfset resetArgs = duplicate( passArgs ) />
								
                                <cfloop query="rs_dep">
									<cfset structInsert( resetArgs, "DEP", rs_dep.institute_id, true ) />
									<cfif depId eq rs_dep.institute_id>
										<span class="opBtn"><cfoutput>#rs_dep.institute_short#</cfoutput></span>
										<cfelse>
										<a class="opBtn" href="<cfoutput>#buildURL('planTask', resetArgs)#</cfoutput>"><cfoutput>#rs_dep.institute_short#</cfoutput></a>
									</cfif>
								</cfloop>

								<cfset structDelete( resetArgs, "DEP", false ) />
								<cfif event.isArgDefined("DEP")>
									<a class="opBtn" href="<cfoutput>#buildURL('planTask', resetArgs)#</cfoutput>">不限</a>
								</cfif>
							</div>
						</div>
						
						
						
						<div class="UIArrangeOper">
						
							<b class="lable">筛选</b>
							<div class="content">
								
								<cfset resetArgs = duplicate( passArgs ) />

								<cfif listFind( filter, "ArrangeDescribe", "," ) >
										<span class="opBtn">有排课要求</span>
									<cfelse>
										<cfset structInsert(resetArgs, "FT", listAppend( filter, "ArrangeDescribe", "," ), true) />
										<a class="opBtn" href="<cfoutput>#buildURL('planTask', resetArgs)#</cfoutput>">有排课要求</a>
								</cfif>
								
								<cfif listFind( filter, "ToArrange", "," ) >
										<span class="opBtn">未排课</span>
									<cfelse>
										<cfset structInsert(resetArgs, "FT", listAppend( filter, "ToArrange", "," ), true) />
										<a class="opBtn" href="<cfoutput>#buildURL('planTask', resetArgs)#</cfoutput>">未排课</a>
								</cfif>
								
								<cfif listFind( filter, "UnComplate", "," ) >
										<span class="opBtn">部分安排</span>
									<cfelse>
										<cfset structInsert(resetArgs, "FT", listAppend( filter, "UnComplate", "," ), true) />
										<a class="opBtn" href="<cfoutput>#buildURL('planTask', resetArgs)#</cfoutput>">部分安排</a>
								</cfif>
								
								<cfif listFind( filter, "OverPeriod", "," ) >
										<span class="opBtn">学时多排</span>
									<cfelse>
										<cfset structInsert(resetArgs, "FT", listAppend( filter, "OverPeriod", "," ), true) />
										<a class="opBtn" href="<cfoutput>#buildURL('planTask', resetArgs)#</cfoutput>">学时多排</a>
								</cfif>
								
								<cfif listFind( filter, "NoPlace", "," ) >
										<span class="opBtn">未排地点</span>
									<cfelse>
										<cfset structInsert(resetArgs, "FT", listAppend( filter, "NoPlace", "," ), true) />
										<a class="opBtn" href="<cfoutput>#buildURL('planTask', resetArgs)#</cfoutput>">未排地点</a>
								</cfif>
								
								<cfset structDelete( resetArgs, "FT", false ) />
								<cfif event.isArgDefined("FT")>
									<a class="opBtn" href="<cfoutput>#buildURL('planTask', resetArgs)#</cfoutput>">不限</a>
								</cfif>
								
							</div>
							
							<div class="content">
								
								<cfset resetArgs = duplicate( passArgs ) />
								
								<cfif courseProp eq "Required" >
										<span class="opBtn">必修</span>
									<cfelse>
										<cfset structInsert(resetArgs, "CP", "Required", true) />
										<a class="opBtn" href="<cfoutput>#buildURL('planTask', resetArgs)#</cfoutput>">必修</a>
								</cfif>
								
								<cfif courseProp eq "Optional" >
										<span class="opBtn">选修</span>
									<cfelse>
										<cfset structInsert(resetArgs, "CP", "Optional", true) />
										<a class="opBtn" href="<cfoutput>#buildURL('planTask', resetArgs)#</cfoutput>">选修</a>
								</cfif>

								<cfset structDelete(resetArgs, "CP", false) />
								<cfif event.isArgDefined("CP")>
									<a class="opBtn" href="<cfoutput>#buildURL('planTask', resetArgs)#</cfoutput>">不限</a>
								</cfif>	
								
							</div>
						</div>
					
					
						<div class="UIArrangeOper mbl">
						
							<b class="lable">课程</b>
							<div class="content">
					
								<form id="courseRouter" class="formRouter" method="post" enctype="application/x-www-form-urlencoded" action="<cfoutput>#buildURL('planTask', passArgs)#</cfoutput>">

									<!--- 课程筛选条件 --->
									<cfif len(period)>
										<input type="hidden" name="PR" value="<cfoutput>#period#</cfoutput>" />
									</cfif>
									<cfif len(filter)>
										<input type="hidden" name="FT" value="<cfoutput>#filter#</cfoutput>" />
									</cfif>
									<cfif len(depId)>
										<input type="hidden" name="DEP" value="<cfoutput>#depId#</cfoutput>" />
									</cfif>
									<cfif len(courseProp)>
										<input type="hidden" name="CP" value="<cfoutput>#courseProp#</cfoutput>" />
									</cfif>

									<cfif rs_course.recordCount>
										
										<a class="botton" href="javascript:previousCourse()">上一门</a>
										<select id="courseList" name="CID" onChange="changeCourse();">
											<cfset row = 0 />
                                            <cfloop query="rs_course">
												<option <cfif (courseId eq rs_course.cid)>selected="selected"</cfif> idx="<cfoutput>#row#</cfoutput>" value="<cfoutput>#rs_course.cid#</cfoutput>">[<cfoutput>#rs_course.institute_short#</cfoutput>] - <cfoutput>#rs_course.course_name#</cfoutput> - <cfoutput>#numberFormat(rs_course.course_credit, "_.00")#</cfoutput>学分</option>
												<cfset row++ />
											</cfloop>
										</select>
										<a class="botton" href="javascript:nextCourse()">下一门</a>

										<span style="margin-left:20px;">排课进度:</span>
										<span class="iconProg L<cfoutput>#progL#</cfoutput>"></span>
										<span class="smallNum"><cfoutput>#numberformat(prog, "__._")#</cfoutput>%</span>

										<cfset row = 0 />
										<script language="javascript" type="text/javascript">
											//<![CDATA[
											<!--
												var courseArray = [<cfloop query="rs_course"><cfset row++ />['<cfoutput>#rs_course.cid#</cfoutput>','<cfoutput>#rs_course.course_name#</cfoutput>']<cfif rs_course.recordCount gt row>,</cfif></cfloop>];
							
												function changeCourse() {
													$("#courseRouter").submit();
												}
							
												function previousCourse() {
								
													var $op = $("#courseList").selectedOptions();

													var count = courseArray.length;
													var idx = parseInt($op.attr("idx"));
								
													if (idx > 0) {
														idx--;
														$("#courseList").val(courseArray[idx][0]);
														$("#courseRouter").submit();
													}
												}
							
												function nextCourse() {
								
													var $op = $("#courseList").selectedOptions();

													var count = courseArray.length;
													var idx = parseInt($op.attr("idx"));
															
													if (idx+1 < count) {
														idx++;
														$("#courseList").val(courseArray[idx][0]);
														$("#courseRouter").submit();
													}
												}
											// -->
											//]]>
										</script>
							
									</cfif>
						
								</form>
							</div>
						</div>
						
						<hr/>
					</div>

					<!--- 如果定义了课程 courseId --->
					<cfif rs_targetCourseEntity.recordCount>

						<div class="noticeBlock">
							<h3>《<cfoutput>#rs_targetCourseEntity.course_name#</cfoutput>》 任课单位: <cfoutput>#rs_targetCourseEntity.institute_name#</cfoutput></h3>
							<p><span class="img icon16x16 message"></span>总学时 <em><cfoutput>#rs_targetCourseEntity.period#</cfoutput></em>, 其中理论学时 <em><cfoutput>#rs_targetCourseEntity.period_theory#</cfoutput></em>. 课程总学分:<em><cfoutput>#numberFormat(rs_targetCourseEntity.course_credit, '_.00')#</cfoutput></em></p>
							
							<div class="UIArrangeOper rtl mtl mbl">
								<cfif showCourseArrangeMode>
									<a class="opBtn Spe" href="javascript:modeCourseTask('<cfoutput>#termId#</cfoutput>','<cfoutput>#courseId#</cfoutput>','2');">此门课程按人排课</a>
								</cfif>
								<a class="opBtn Spe" href="javascript:clearCourseTask('<cfoutput>#termId#</cfoutput>','<cfoutput>#courseId#</cfoutput>');">清除此门课程排课结果</a>
							</div>
							
							
						</div>
					</cfif>

					<cfif rs_task.recordCount>
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="30"></td>
									<td>教师</td>
									<td width="30">周次</td>
									<td width="24">学时</td>
									<td>人数</td>
									<td>校区</td>
									<td>场地要求</td>
									<td nowrap="nowrap">上课时间</td>
									<td nowrap="nowrap">上课地点</td>
									<td>排课要求</td>
									<td align="right" width="48">排课学时</td>
									<td width="80"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_task">
									
									<cfset row++ />
									<cfset structInsert(passArgs, "TSK", rs_task.task_id, true) />
									<cfset structInsert(passArgs, "CID", rs_task.cid, true) />
									<cfset structInsert(passArgs, "TT", rs_task.task_type, true) />

									<cfif period neq "">
										<cfset structInsert(passArgs, "PR", period, true) />
									</cfif>
									<cfif filter neq "">
										<cfset structInsert(passArgs, "FT", filter, true) />
									</cfif>
									<cfif depId neq "">
										<cfset structInsert(passArgs, "DEP", depId, true) />
									</cfif>
									<cfif courseProp neq "">
										<cfset structInsert(passArgs, "CP", courseProp, true) />
									</cfif>
									
									<cfset taskProp.parseProperty(rs_task.task_prop) />
									
									<tr class="editRows <cfif taskProp.getCancel()>cancelRow</cfif>" rowid="<cfoutput>#rs_task.task_id#</cfoutput>">
										<td>
											<cfif event.getArg("TSK") eq rs_task.task_id>
												<span class="stat select"></span>
												<cfelse>
												<span class="index"><cfoutput>#rs_task.cidx#</cfoutput></span>
											</cfif>
										</td>
										<td nowrap="nowrap"><cfoutput>#rs_task.tch_name#</cfoutput></td>
										<td nowrap="nowrap"><span class="numeric"><cfoutput>#rs_task.task_week#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_task.task_period#</cfoutput></span></td>
										<td nowrap="nowrap"><span class="numeric"><cfoutput>#rs_task.task_chooesd#</cfoutput> / <cfoutput>#rs_task.task_limite#</cfoutput></span></td>
										<td nowrap="nowrap"><cfoutput>#rs_task.campus_name#</cfoutput></td>
										<td nowrap="nowrap"><cfoutput>#rs_task.cr_type_name#</cfoutput></td>
										<td nowrap="nowrap"><span class="numeric"><cfoutput>#replace(rs_task.task_time, ",", "<br/>", "all")#</cfoutput></span></td>
										<td nowrap="nowrap"><cfoutput>#replace(rs_task.task_place, ",", "<br/>", "all")#</cfoutput></td>
										<td><cfoutput>#rs_task.task_desc#</cfoutput></td>
										<td align="right"><span class="numeric"><cfoutput>#rs_task.period_done#</cfoutput> / <cfoutput>#rs_task.period_need#</cfoutput></span></td>

										<cfif taskProp.getCancel()>
												<td align="right">已撤班</td>
											<cfelse>
												<td align="right">
													<cfif taskProp.getArrangeDone()>
															<!--- 排课结果已锁定 --->
															<a title="解锁任务" class="stat locked" href="javascript:unlockTask('<cfoutput>#rs_task.task_id#</cfoutput>');"></a>
														<cfelse>
															<cfset structInsert(passArgs, "Tab", "labCourseTable", true) />
															<cfset structInsert(passArgs, "showTab", 1, true) />
																<a title="仅安排上课时间" class="stat settime" href="<cfoutput>#buildURL('planTaskSetTime', passArgs)#</cfoutput>"></a>
															<cfif rs_task.task_period neq "0">
															<a title="排课" class="stat arrange" href="<cfoutput>#buildURL('planTaskArrange', passArgs)#</cfoutput>"></a>
																</cfif>
															<cfif rs_task.period_done gte rs_task.period_need>
																<!--- 排课结果未锁定 --->
																<a title="锁定教学任务" class="stat unlock" href="javascript:lockTask('<cfoutput>#rs_task.task_id#</cfoutput>');"></a>
															</cfif>
													</cfif>
											</td>
										</cfif>
									</tr>
								</cfloop>
							</tbody>
						</table>
						
						<cfset reloadArgs = structNew() />
						
						<cfset structInsert(reloadArgs, "TT", "P", true) />

						<cfif termId neq ""><cfset structInsert(reloadArgs, "TID", termId, true) /></cfif>
						<cfif courseId neq ""><cfset structInsert(reloadArgs, "CID", courseId, true) /></cfif>
						<cfif period neq ""><cfset structInsert(reloadArgs, "PR", period, true) /></cfif>
						<cfif filter neq ""><cfset structInsert(reloadArgs, "FT", filter, true) /></cfif>
						<cfif depId neq ""><cfset structInsert(reloadArgs, "DEP", depId, true) /></cfif>
						<cfif courseProp neq ""><cfset structInsert(reloadArgs, "CP", courseProp, true) /></cfif>
						
						<!--- 对于 javascript 地址 &amp; 需要重新转义为 & 避免 google chrome 浏览器无法正确识别地址 --->
						<cfset reloadURL = replace( buildURL( "planTask", reloadArgs), "&amp;", "&", "all") />
						
						<div id="test"></div>
						<script language="javascript" type="text/javascript">
							//<![CDATA[
							<!--
							
							function modeCourseTask(termId, courseId, mode) {
								
								/* 显示阻挡信息 */
								$.blockUI({ 
											message: '更改排课模式...',
											css: { 
													'width': '16%',
													'left': '42%',
													'border': 'none', 
													'padding': '15px 5px', 
													'backgroundColor': '#090', 
													'border-radius': '4px', 
													'opacity': .8, 
													'color': '#fff',
													'cursor': null
													},
											overlayCSS: {
													'backgroundColor': '#000', 
													'opacity': .1 ,
													'cursor': null
													}
											}); 
								
								$.post(
										"<cfoutput>#buildURL('apiCourseArrangeMode')#</cfoutput>", 
										{
											'TID' : termId,
											'CID' : courseId,
											'MODE' : mode,
											'seed': (new Date()).getTime()
										}, 
										function(data) {
											
											result = $.parseJSON(data);
										
											if (result.success) {
												/* 刷新排课数据 */
												window.location = '<cfoutput>#reloadURL#</cfoutput>';
											}
											else {
												
												/* 取消阻挡 */
												$.unblockUI();
												
												alert(result.reason);
											}
											
										});								
							}
							
							function clearCourseTask(termId, courseId){
								
								/* 显示阻挡信息 */
								$.blockUI({ 
											message: '删除课程排课...',
											css: { 
													'width': '16%',
													'left': '42%',
													'border': 'none', 
													'padding': '15px 5px', 
													'backgroundColor': '#900', 
													'border-radius': '4px', 
													'opacity': .8, 
													'color': '#fff',
													'cursor': null
													},
											overlayCSS: {
													'backgroundColor': '#000', 
													'opacity': .1 ,
													'cursor': null
													}
											}); 
								
								$.post(
										"<cfoutput>#buildURL('apiCourseTaskClear')#</cfoutput>", 
										{
											'TID' : termId,
											'CID' : courseId,
											'seed': (new Date()).getTime()
										}, 
										function(data) {
											
											//$("#test").html(data);
											
											result = $.parseJSON(data);
										
											if (result.success) {
												/* 刷新排课数据 */
												window.location = '<cfoutput>#reloadURL#</cfoutput>';
											}
											else {
												
												/* 取消阻挡 */
												$.unblockUI();
												
												alert(result.reason);
											}
											
										});
								
							}
							
							function lockTask(taskId){
								
								/* 显示阻挡信息 */
								$.blockUI({ 
											message: '锁定教学任务...',
											css: { 
													'width': '16%',
													'left': '42%',
													'border': 'none', 
													'padding': '15px 5px', 
													'backgroundColor': '#090', 
													'border-radius': '4px', 
													'opacity': .8, 
													'color': '#fff',
													'cursor': null
													},
											overlayCSS: {
													'backgroundColor': '#000', 
													'opacity': .1 ,
													'cursor': null
													}
											});
								
								$.post(
										"<cfoutput>#buildURL('apiTaskLockPropChange')#</cfoutput>", 
										{
											'TSK' : taskId,
											'TT' : 'P',
											'status': true,
											'seed': (new Date()).getTime()
										}, 
										function(data) {
										
											result = $.parseJSON(data);
										
											if (result.success) {
												/* 刷新排课数据 */
												window.location = '<cfoutput>#reloadURL#</cfoutput>';
											}
											else {
												
												/* 取消阻挡 */
												$.unblockUI();
												
												alert(result.reason);
											}
											
										});
							
							}
							
							function unlockTask(taskId){
								
								/* 显示阻挡信息 */
								$.blockUI({ 
											message: '解锁教学任务...',
											css: { 
													'width': '16%',
													'left': '42%',
													'border': 'none', 
													'padding': '15px 5px', 
													'backgroundColor': '#090', 
													'border-radius': '4px', 
													'opacity': .8, 
													'color': '#fff',
													'cursor': null
													},
											overlayCSS: {
													'backgroundColor': '#000', 
													'opacity': .1 ,
													'cursor': null
													}
											});
								
								$.post(
										"<cfoutput>#buildURL('apiTaskLockPropChange')#</cfoutput>", 
										{
											'TSK' : taskId,
											'TT' : 'P',
											'status': false,
											'seed': (new Date()).getTime()
										}, 
										function(data) {
										
											result = $.parseJSON(data);
										
											if (result.success) {
												/* 刷新排课数据 */
												window.location = '<cfoutput>#reloadURL#</cfoutput>';
											}
											else {
												
												/* 取消阻挡 */
												$.unblockUI();
												
												alert(result.reason);
											}
											
										});
							
							}
							// -->
							//]]>
						</script>
						
					</cfif>
					
				</div>
				
				<div id="CourseTable" class="tabContent">
					<!--- 排课控制 --->
					<!-- courseArrange-->
					<cfoutput>#event.getArg("courseArrange")#</cfoutput>
					<!--/courseArrange-->
				</div>
				
				<div id="TimeSet" class="tabContent">
					
					<div class="noticeBlock">
						<h3>设置计划类课程的排课可用时间</h3>
						<p><span class="img icon16x16 message"></span>为了提高计划课程自动排课的成功率, 请尽量使用周一至周五所有的可用时间段, 以最大程度的利用教室资源.</p>
						<hr/>
					</div>
					
					
					<table class="UICourseTable">
						<thead>
							<tr>
								<td colspan="2" width="2%"></td>
								<td width="14%">星期一</td>
								<td width="14%">星期二</td>
								<td width="14%">星期三</td>
								<td width="14%">星期四</td>
								<td width="14%">星期五</td>
								<td width="14%">星期六</td>
								<td width="14%">星期天</td>
							</tr>
						</thead>
						<tbody>
							<cfloop from="1" to="6" index="lec">
							<tr>
								<cfswitch expression="#lec#">
									<cfcase value="1"><td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td></cfcase>
									<cfcase value="3"><td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td></cfcase>
									<cfcase value="5"><td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td></cfcase>
								</cfswitch>
								<td><cfoutput>#mathAdvice.convertLectureIdxToChinese(lec)#</cfoutput></td>
								<cfloop from="1" to="7" index="wkday">
								<td id="tbcLEC<cfoutput>#wkday#</cfoutput><cfoutput>#lec#</cfoutput>" class="<cfif timeTable[wkday][lec]>yes<cfelse>no</cfif>">
								<cfif timeTable[wkday][lec]>
									<a id="tbLEC<cfoutput>#wkday#</cfoutput><cfoutput>#lec#</cfoutput>" class="botton yes" href="javascript:tableSet(<cfoutput>#wkday#</cfoutput>,<cfoutput>#lec#</cfoutput>);">可排</a>
									<cfelse>
									<a id="tbLEC<cfoutput>#wkday#</cfoutput><cfoutput>#lec#</cfoutput>" class="botton no" href="javascript:tableSet(<cfoutput>#wkday#</cfoutput>,<cfoutput>#lec#</cfoutput>);">禁用</a>
								</cfif>
								</td>
								</cfloop>
							</tr>
							</cfloop>
						</tbody>
					</table>

					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						function tableSet(weekDay, lecture){
							
							var $trigger = $("#tbLEC" + weekDay + lecture);
							var $cell = $("#tbcLEC" + weekDay + lecture);
							
							var status = $trigger.hasClass("yes");
							var newStatus = true;
							
							/* 切换状态数据 */
							if (status) {
								newStatus = false;
							}
							
							/* 显示阻挡信息 */
							$.blockUI({ 
										message: '变更可用时间...',
										css: { 
												'width': '16%',
												'left': '42%',
												'border': 'none', 
												'padding': '15px 5px', 
												'backgroundColor': '#090', 
												'border-radius': '4px', 
												'opacity': .8, 
												'color': '#fff',
												'cursor': null
												},
										overlayCSS: {
												'backgroundColor': '#fff', 
												'opacity': .1 ,
												'cursor': null
												}
										});
							
							$.post(
									"<cfoutput>#buildURL('apiTimeTablePropChange')#</cfoutput>", 
									{
										'wkday' : weekDay,
										'lec' : lecture,
										'method' : 'ProgramTask',
										'status' : newStatus,
										'seed': (new Date()).getTime()
									}, 
									function(data) {
										
										result = $.parseJSON(data);

										/* 刷新时间状态数据 */
										
										if (result.ProgramTask) { 
											$trigger.text("可排").removeClass("no").addClass("yes"); 
											$cell.removeClass("no").addClass("yes"); 
										} 
										else { 
											$trigger.text("禁用").removeClass("yes").addClass("no"); 
											$cell.removeClass("yes").addClass("no"); 
										}
										
										/* 取消阻挡 */
										$.unblockUI();
										
									});
							
						}
						// -->
						//]]>
					</script>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>